package com.example.admin.SQLite.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.example.admin.SQLite.Complaint;
import com.example.admin.SQLite.SqLiteOpenHelper;
import com.example.admin.SQLite.TongZhi;

import java.util.ArrayList;

import static com.example.admin.SQLite.SqLiteOpenHelper.FEIYONG;
import static com.example.admin.SQLite.SqLiteOpenHelper.TONGZHI;

public class TongZhiDao {
    SqLiteOpenHelper dbHelper;
    private static final String KEY_ID = "id";

    public TongZhiDao(Context context) {
        dbHelper = new SqLiteOpenHelper(context);
    }

    public long addData(TongZhi bean) {
        SQLiteDatabase db = dbHelper.getSqlite();
        ContentValues values = new ContentValues();
        values.put("tongzhiTitle", bean.tongzhiTitle);
        values.put("tongzhiContent", bean.tongzhiContent);
        values.put("tongzhiTime", bean.tongzhiTime);
        long id = db.insert(TONGZHI, null, values);
        Log.e("的收费收费的方式", "addData: " + id);
        return id;
    }

    public void DeleteContacts(int id) {
        SQLiteDatabase database = dbHelper.getSqlite();
        database.delete(TONGZHI, KEY_ID + " = ? ", new String[]{String.valueOf(id)});
    }
    public ArrayList<TongZhi> FindWhereData() {
        SQLiteDatabase db = dbHelper.getSqlite();
        Cursor cursor = db.rawQuery("SELECT * FROM " + TONGZHI, null);
        ArrayList<TongZhi> arrContacts = new ArrayList<>();

        while (cursor.moveToNext()) {
            TongZhi model = new TongZhi();
            model.id = cursor.getInt(0);
            model.tongzhiTitle = cursor.getString(1);
            model.tongzhiContent = cursor.getString(2);
            model.tongzhiTime = cursor.getString(3);

            arrContacts.add(model);

        }
        return arrContacts;
    }

}
